package ai.peanut.one.api.tread.test2;

public class ProduAndConsume {
    int a  = 19;
    private final  static int max = 20 ;
    private  final  static  int min = 10 ;

    public synchronized  void pro(){


        if( a >= max ) {
            try
            {
                System.out.println("生产达到峰值，请取货");
                wait();

                return ;
            }
            catch (InterruptedException e)
            {
                e.printStackTrace();
            }
            return;
        }

        System.out.println("开始生产" + a);
        a++ ;
        notifyAll();
    }

    public synchronized  void csu(){
        if( a <= min ){
            try
            {
                System.out.println("缺货,稍候再取");
                wait();

                return ;
            }
            catch (InterruptedException e)
            {
                e.printStackTrace();
            }
            return;
        }
        System.out.println("开始取货" + a);
        a -- ;
        notifyAll();
    }
}
